package org.naxx.security.xgen.util;

import java.io.IOException;
import java.io.Writer;

/**
 * Appends new line character on each call to write(String) method.
 * It does not override any other methods of the underlying
 * Writer.
 */
public class XWriter extends Writer {

	private Writer underlyingWriter;
	
	public XWriter(Writer underlyingWriter) {
		this.underlyingWriter = underlyingWriter;
	}
	
	@Override
	public void close() throws IOException {
		this.underlyingWriter.close();
	}

	@Override
	public void flush() throws IOException {
		this.underlyingWriter.flush();
	}

	@Override
	public void write(char[] cbuf, int off, int len) throws IOException {
		this.underlyingWriter.write(cbuf, off, len);
	}

	/**
	 * Just append new line character at the end of string.
	 * Perhaps we could add tab prefix insertion as well.
	 */
	public void write(String str) throws IOException {
		super.write(str + "\n");
	}
}
